home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-admin / plugins.php < prev    next >
Encoding:
PHP Script  |  2004-05-18  |  4.7 KB  |  148 lines

  1. <?php
  2.  
  3. if (isset($_GET['action'])) {
  4.     $standalone = 1;
  5.     require_once('admin-header.php');
  6.  
  7.     check_admin_referer();
  8.  
  9.     if ('activate' == $_GET['action']) {
  10.         $current = "\n" . get_settings('active_plugins') . "\n";
  11.         $current = preg_replace("|(\n)+\s*|", "\n", $current);
  12.         $current = trim($current) . "\n " . trim($_GET['plugin']);
  13.         $current = trim($current);
  14.         $current = preg_replace("|\n\s*|", "\n", $current); // I don't know where this is coming from
  15.         update_option('active_plugins', $current);
  16.         header('Location: plugins.php?activate=true');
  17.     }
  18.     
  19.     if ('deactivate' == $_GET['action']) {
  20.         $current = "\n" . get_settings('active_plugins') . "\n";
  21.         $current = str_replace("\n" . $_GET['plugin'], '', $current);
  22.         $current = preg_replace("|(\n)+\s*|", "\n", $current);
  23.         update_option('active_plugins', trim($current));
  24.         header('Location: plugins.php?deactivate=true');
  25.     }
  26. }
  27.  
  28. require_once('../wp-includes/wp-l10n.php');
  29. $title = __('Manage Plugins');
  30. require_once('admin-header.php');
  31.  
  32. if ($user_level < 9) // Must be at least level 9
  33.     die (__("Sorry, you must be at least a level 8 user to modify plugins."));
  34.  
  35. // Clean up options
  36. // if any files are in the option that don't exist, axe 'em
  37.  
  38. $check_plugins = explode("\n", (get_settings('active_plugins')));
  39. foreach ($check_plugins as $check_plugin) {
  40.     if (!file_exists(ABSPATH . 'wp-content/plugins/' . $check_plugin)) {
  41.             $current = get_settings('active_plugins') . "\n";
  42.             $current = str_replace($check_plugin . "\n", '', $current);
  43.             $current = preg_replace("|\n+|", "\n", $current);
  44.             update_option('active_plugins', trim($current));
  45.     }
  46. }
  47.  
  48.  
  49.  
  50. ?>
  51.  
  52. <?php if (isset($_GET['activate'])) : ?>
  53. <div class="updated"><p><?php _e('Plugin <strong>activated</strong>.') ?></p>
  54. </div>
  55. <?php endif; ?>
  56. <?php if (isset($_GET['deactivate'])) : ?>
  57. <div class="updated"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p>
  58. </div>
  59. <?php endif; ?>
  60.  
  61. <div class="wrap">
  62. <h2><?php _e('Plugin Management'); ?></h2>
  63. <p><?php _e('Plugins are files you usually download seperately from WordPress that add functionality. To install a plugin you generally just need to put the plugin file into your <code>wp-content/plugins</code> directory. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p>
  64. <?php
  65. // Files in wp-content/plugins directory
  66. $plugins_dir = @ dir(ABSPATH . 'wp-content/plugins');
  67. if ($plugins_dir) {
  68.     while(($file = $plugins_dir->read()) !== false) {
  69.       if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) 
  70.         $plugin_files[] = $file;
  71.     }
  72. }
  73.  
  74. if ('' != trim(get_settings('active_plugins'))) {
  75.     $current_plugins = explode("\n", (get_settings('active_plugins')));
  76. }
  77.  
  78. if (!$plugins_dir || !$plugin_files) {
  79.     _e("<p>Couldn't open plugins directory or there are no plugins available.</p>"); // TODO: make more helpful
  80. } else {
  81. ?>
  82. <table width="100%" cellpadding="3" cellspacing="3">
  83.     <tr>
  84.         <th><?php _e('Plugin'); ?></th>
  85.         <th><?php _e('Version'); ?></th>
  86.         <th><?php _e('Author'); ?></th>
  87.         <th><?php _e('Description'); ?></th>
  88.         <th><?php _e('Action'); ?></th>
  89.     </tr>
  90. <?php
  91.     sort($plugin_files); // Alphabetize by filename. Better way?
  92.     $style = '';
  93.     foreach($plugin_files as $plugin_file) {
  94.         $plugin_data = implode('', file(ABSPATH . '/wp-content/plugins/' . $plugin_file));
  95.         preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
  96.         preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
  97.         preg_match("|Description:(.*)|i", $plugin_data, $description);
  98.         preg_match("|Author:(.*)|i", $plugin_data, $author_name);
  99.         preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
  100.         if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
  101.             $version = $version[1];
  102.         else
  103.             $version ='';
  104.  
  105.         $description = wptexturize($description[1]);
  106.  
  107.         if ('' == $plugin_uri) {
  108.             $plugin = $plugin_name[1];
  109.         } else {
  110.             $plugin = __("<a href='{$plugin_uri[1]}' title='Visit plugin homepage'>{$plugin_name[1]}</a>");
  111.         }
  112.  
  113.         if ('' == $author_uri) {
  114.             $author = $author_name[1];
  115.         } else {
  116.             $author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");
  117.         }
  118.  
  119.  
  120.  
  121.         $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
  122.  
  123.         if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
  124.             $action = __("<a href='plugins.php?action=deactivate&plugin=$plugin_file' title='Deactivate this plugin' class='delete'>Deactivate</a>");
  125.             $plugin = __("<strong>$plugin</strong>");
  126.         } else {
  127.             $action = __("<a href='plugins.php?action=activate&plugin=$plugin_file' title='Activate this plugin' class='edit'>Activate</a>");
  128.         }
  129.         echo "
  130.     <tr $style>
  131.         <td>$plugin</td>
  132.         <td>$version</td>
  133.         <td>$author</td>
  134.         <td>$description</td>
  135.         <td>$action</td>
  136.     </tr>";
  137.     }
  138. ?>
  139.  
  140. </table>
  141. <?php
  142. }
  143. ?>
  144. </div>
  145.  
  146. <?php
  147. include('admin-footer.php');
  148. ?>